/*================================================================*
        Copyright (C) 2021 All rights reserved www.hsby.link
      	�ļ����ƣ�test_http.cc
      	�� �� �ߣ���ɭ����
      	�������ڣ�2021/12/24
 *================================================================*/
#include "log.h"
#include "http/http.h"
#include "http/http_paser.h"

void test_req() {
    auto req = hsby::http::HttpRequest::Create();
    req->SetMethod(hsby::http::HttpMethod::GET);
    req->SetHeader("host", "www.hsby.link");
    req->SetBody("Hello World");
    //HSBY_LOG_SYSTEM_DEBUG << "\n" << req->ToString();
}

void test_rsp() {
    auto rsp = hsby::http::HttpResponse::Create();
    rsp->SetStatus(hsby::http::HttpStatus::BAD_REQUEST);
    rsp->SetHeader("xxx", "www.hsby.link");
    rsp->SetBody("Hello World");
    //HSBY_LOG_SYSTEM_DEBUG << "\n" << rsp->ToString();
}

void test_request() {
    auto req = hsby::http::HttpRequest::Create();
    req->SetMethod(hsby::http::HttpMethod::GET);
    req->SetHeader("host", "www.hsby.link");
    req->SetBody("Hello World");
    auto req_string = req->ToString();
    //HSBY_LOG_SYSTEM_DEBUG << req_string;

    hsby::http::HttpRequestParser http_request_parser;
    http_request_parser.Parse(req_string.c_str(), req_string.size());
    auto parse_req = http_request_parser.GetRequest();
    //HSBY_LOG_SYSTEM_DEBUG << parse_req->ToString();
}

void test_response() {
//    auto rsp = hsby::http::HttpResponse::Create();
//    rsp->SetStatus(hsby::http::HttpStatus::OK);
//    rsp->SetBody("Hello World");
//    auto rsp_str = rsp->ToString();
//    //HSBY_LOG_SYSTEM_DEBUG << rsp_str;

    const char* rsp_chs = "HTTP/1.1 200 OK\r\n"
                          "Date: Tue, 04 Jun 2019 15:43:56 GMT\r\n"
                          "Server: Apache\r\n"
                          "Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT\r\n"
                          "ETag: \"51-47cf7e6ee8400\"\r\n"
                          "Accept-Ranges: bytes\r\n"
                          "Content-Length: 84\r\n"
                          "Cache-Control: max-age=86400\r\n"
                          "Expires: Wed, 05 Jun 2019 15:43:56 GMT\r\n"
                          "Connection: Close\r\n"
                          "Content-Type: text/html\r\n\r\n"
                          "<html>\r\n"
                          "<meta http-equiv=\"refresh\" content=\"0;url=http://www.baidu.com/\">\r\n"
                          "</html>\r\n";
    hsby::http::HttpResponseParser http_response_parser;
    http_response_parser.Parse(rsp_chs, strlen(rsp_chs), 0, true);
}

int main() {
    test_response();
    return 0;
}